cap confirm file "$data_out/Flags.dta" 
if _rc!=0 { 
do "$Outcomes/Flags.do"
}
else use "$data_out/Flags.dta", clear 

do "$Outcomes/Flags.do"


label var ed_prescription "Prescription in ED"
label var any_flag "Any Flag within 1 Year"
label var any_flag2  "Any Flag within 2 Years"
label var substance_flag "Drug or Alcohol Flag within 1 Year"
label var substance_flag2 "Drug or Alcohol Flag within 2 Years"
label var adverse_flag "Discipline Flag within 1 Year"
label var adverse_flag2 "Discipline Flag within 2 Years"



foreach outcome in   adverse_flag crime_flag substance_flag adverse_flag2 crime_flag2 substance_flag2   {
eststo `outcome'_C:	ivreghdfe `outcome' $spec1 
estadd ysumm, replace

eststo `outcome'_Q:	ivreghdfe `outcome' $spec2
estadd ysumm, replace 
}

#delimit ;

	//word
esttab adverse_flag_C adverse_flag2_C crime_flag_C crime_flag2_C substance_flag_C substance_flag2_C using "flags.rtf" , 
	replace label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(ymean N ,
	fmt(a2 %-9.0fc)
	label("Sample Mean" "Observations"))
		keep(ed_prescription)
		title(IV Results for Disciplinary Actions - Prescribing Rate Instrument);
		
	
esttab adverse_flag_Q adverse_flag2_Q crime_flag_Q crime_flag2_Q substance_flag_Q substance_flag2_Q  using "flags.rtf" , 
	append label se star(* 0.10 ** 0.05 *** 0.01)
	b(4) se(4)
	stats(ymean N ,
	fmt(a2 %-9.0fc)
	label("Sample Mean" "Observations"))
		keep(ed_prescription)
		title(IV Results for Disciplinary Actions - 4th vs 1st Quartile Instrument);
		
 
#delimit cr


